package service;

import java.util.List;
import java.util.Set;

import models.Book;
import models.Borrow;
import models.Indent;

public class OrderService {

	public static int getMaxBookJ(String userid){
		List<Indent> inds = Indent.find("memid=?", userid).fetch();
		int i = 0;
		for(Indent ind : inds){
			Set<Borrow> os = ind.borrows;
			for(Borrow b : os){
				i += b.boramo;
			}
		}
		return i;
	}
	
	/**
	 * 拆分session中的数据
	 * @param str      的数据格式是**(图书id).**(借阅数量) 
	 * @return
	 */
	public static Object[] strToObj(String str){
		String[] s = null;
		Object[] sd = new Object[2];
		try{
		if(str != null && !"".equals(str.trim())){
			s = str.split("\\.");
			if(s.length > 0){
				String id = s[0];
				Long lid = Long.parseLong(id);
				Book b = Book.findById(lid);
				if(b != null){
					sd[0] = b;
				}
				sd[1] = s[1];
			}
		}
		}catch(Exception e){
			sd = null;
		}
		return sd;
	}
	
	/**
	 * 根据会员id获取会员借过的未还的书籍总数
	 * @param uid
	 * @return
	 */
	public static int getBooCount(String uid){
		int i = 0;
		try{
			List<Indent> inds = Indent.find("memid=?", uid).fetch();
			for(Indent ind : inds){
				for(Borrow b : ind.borrows){
					if(b.borsta != 0){
						i += b.boramo;
					}
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return i;
	}
	
	public static int getMaxHuans(Long borrow){
		int day = 0;
		try{
			
		}catch(Exception e){}
		return day;
	}
}
